package com.tutorial.springboot.controller;

import com.tutorial.springboot.document.Post;
import com.tutorial.springboot.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by louchen on 2016/11/16.
 */
@RestController
@RequestMapping(value = "/posts")
public class PostController {

    @Autowired
    private PostService postService;

    @RequestMapping(value = "/one", method = {RequestMethod.GET})
    public List<Post> find(@RequestParam String title){
        List<Post> list = postService.findByTitleLike(title);
        return list;
    }

    @RequestMapping(value = "/one", method = {RequestMethod.POST}, consumes = {MediaType.APPLICATION_JSON_VALUE})
    public Post insertPost(@RequestBody Post post){
        Post afterSave = postService.saveInEs(post);
        return afterSave;
    }

    @RequestMapping(value = "/one", method = {RequestMethod.PUT}, consumes = {MediaType.APPLICATION_JSON_VALUE})
    public String updatePost(){
        return "updatePost";
    }

}
